﻿Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.DAO
Imports DoAnQuanLyBanHang1065043_1065007.DoAnQuanLyBanHang.General
Imports DevComponents.DotNetBar

Public Class frmLoaiGiaoDich
    Private m_LoaiGiaoDichCtrl As New LoaiGiaoDichCtrl()
    Private m_QuyDinh As New QuyDinh()
    Public Sub New()
        InitializeComponent()
        DataService.OpenConnection()
    End Sub

    Private Sub frmLoaiGiaoDich_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        m_LoaiGiaoDichCtrl.HienThi(DGVDMLoaiGiaoDich, BindingNavigatorDMLoaiGiaoDich)

    End Sub

    Private Sub bindingNavigatorAddNewItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorAddNewItem.Click
        If DGVDMLoaiGiaoDich.RowCount = 0 Then
            BindingNavigatorDMLoaiGiaoDich.Enabled = True
        End If
        Dim m_Row As DataRow = m_LoaiGiaoDichCtrl.ThemDongMoi()
        m_Row("MaLoaiGiaoDich") = "GD" & m_QuyDinh.LaySTT(DGVDMLoaiGiaoDich.Rows.Count + 1)
        m_Row("TenLoaiGiaoDich") = ""
        m_LoaiGiaoDichCtrl.ThemMoi(m_Row)
        BindingNavigatorDMLoaiGiaoDich.BindingSource.MoveLast()

    End Sub
    Public Function KiemTraTruocKhiLuu(str As [String]) As [Boolean]
        For Each row As DataGridViewRow In DGVDMLoaiGiaoDich.Rows
            If row.Cells(str).Value IsNot Nothing Then
                Dim m_Str As [String] = row.Cells(str).Value.ToString()
                If m_Str = "" Then
                    Return False
                End If
            End If
        Next
        Return True
    End Function

    Private Sub bindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorSaveItem.Click
        If KiemTraTruocKhiLuu("colMaLoaiGiaoDich") = True AndAlso KiemTraTruocKhiLuu("colTenGiaoDich") = True Then
            bindingNavigatorPositionItem.Focus()
            m_LoaiGiaoDichCtrl.LuuLoaiGiaoDich()
        Else
            MessageBoxEx.Show("Giá trị của ô không được rỗng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End If

    End Sub

    Private Sub bindingNavigatorDeleteItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorDeleteItem.Click
        If DGVDMLoaiGiaoDich.RowCount = 0 Then
            bindingNavigatorDeleteItem.Enabled = False

        ElseIf MessageBox.Show("Bạn có chắc chắn xóa dòng này không?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
            BindingNavigatorDMLoaiGiaoDich.BindingSource.RemoveCurrent()
        End If

    End Sub

    Private Sub bindingNavigatorCloseItem_Click(sender As System.Object, e As System.EventArgs) Handles bindingNavigatorCloseItem.Click
        Me.Close()

    End Sub
End Class